package org.huntaway.material.cleaner.arguments.model.imp;

import java.util.Collection;
import java.util.Iterator;

import org.huntaway.material.cleaner.arguments.model.ArgumentsVisitor;
import org.huntaway.material.cleaner.arguments.model.Visitable;
import org.huntaway.material.cleaner.enumerate.EnumOperate;
import org.huntaway.material.cleaner.model.bean.MaterialBean;
import org.huntaway.material.cleaner.operate.model.InterOperate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ArgsConcreteVisitor implements ArgumentsVisitor {
	private final Logger logger = LoggerFactory.getLogger(ArgsConcreteVisitor.class);
	private InterOperate operate;
	private MaterialBean mateBean=new MaterialBean();
	public ArgsConcreteVisitor(InterOperate oper) {
		operate=oper;
	}

	public void visitCollection(Collection<Visitable> collection) {
		Iterator<Visitable> iterator = collection.iterator();
		while (iterator.hasNext()) {
			Object obj = iterator.next();
			if (obj instanceof Visitable) {
				((Visitable) obj).accept(this);
			}
		}
		processor();
	}

	private void processor() {
		logger.info(getOperStr(mateBean.getOper())+mateBean.getPara());
		switch (mateBean.getOper()) {
		case C:		
			//operate.copy(src, dest);
			operate.copy(mateBean.getPara());
			break;
		case D:	
			//operate.delete(src);
			operate.delete(mateBean.getPara());
			break;
		case G:
			//operate.get(src, dest);
			operate.get(mateBean.getPara());
			break;
		case M:
			//operate.move(src, dest);
			operate.move(mateBean.getPara());
			break;
		case O:
			//operate.open(src);
			operate.open(mateBean.getPara());
			break;
		case R:
			//operate.run(src);
			operate.run(mateBean.getPara());
			break;
		case S:
			//operate.show(src);
			operate.show(mateBean.getPara());
			break;
		}
		
	}

	private String getOperStr(EnumOperate oper) {
		return oper.getCode();
	}

	public void firstProcess(FirstArguments first) {
		mateBean.setOper(first.getOper());
		mateBean.setMedia(first.getMedia());
	}

	public void twoProcess(TwoArguments two) {
		
	}

	public void threeProcess(ThreeArguments three) {
		//dest="";
	}

	public MaterialBean getMateBean() {
		return mateBean;
	}
}
